<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>个人信息</title>
    <script src="../static/js/jquery.min.js"></script>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
    <script src="../static/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="style.css">
    <?php
    require_once "session.php";
    $weixin_id = $_SESSION["user"];
    $user = $core->GetUserByWxId($weixin_id);
    $expend_log=$core->GetUserExpendAndPrize($user["id"]);
    $zt=false;
    for($a=0;$a<count($expend_log);$a++){
        if($expend_log[$a]["allow_barter"]="1"&&$expend_log[$a]["finish_barter"]!="1"){
            $zt=true;
            break;
        }
    }
    /*if(empty($user)){
        $core->AddUser($weixin_id,null,null);
        $user = $core->GetUserByWxId($weixin_id);
    }*/
    $withdraw_money = $core->GetUserWithdrawByUserId($user["id"]);
    $money = 0;
    for ($a = 0; $a < count($withdraw_money); $a++) {
        $money += $withdraw_money[$a]["money"];
    }
    $bank_card = $core->GetCardsByUserId($user["id"]);
    $user_icon = $user["icon"];
    if ($user_icon == null) {
        $user_icon = "../wap/user_icon/Default_icon.png";
    } else {
        if (!preg_match("/^(http:).*$/", $user_icon)) {
            $user_icon = "../wap/user_icon/" . $user["icon"];
        }
    }
    ?>
    <style type="text/css">


        #MainPanel {
            height: 100%;
            overflow-y: auto;
        }

        .modal-backdrop {
            z-index: 998;
        }

        .modal-dialog {
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
            position: absolute;
            height: 150px;
            width: 230px;
        }
    </style>
</head>
<body>
<div id="head" style="display: none;">
    <span style="font-size: 25px;margin-left: 10%">个人信息</span>
    <span class="pull-right" style="float: right"><a href="Help.php" style="color: black;font-size: 20px">帮助</a></span>
</div>

<div id="MainPanel" class="col-xs-12">

    <div class="row">
        <div class="col-xs-12">
            <div class="panel" style="margin-top: 15px;">
                <div class="panel-body">
                    <div class="form-group">
                        <div class="row" style="position: relative;">
                            <div class="col-xs-12">
                                <div class="thumbnail"
                                     style="width: 91px;height: 91px; margin: 0 auto;position: relative;">
                                    <img src="<?php echo $user_icon; ?>">
                                    <form id="save_icon" method="post" enctype="multipart/form-data">
                                        <input id="fileInput" name="icon" type="file"
                                               onchange="input_icon('<?php /*echo $user_icon; */ ?>')">
                                    </form>
                                </div>
                            </div>
                            <a class="btn" href="Help.php" style="position: absolute;right: 20px;">
                                <span class="glyphicon glyphicon-info-sign"></span>
                            </a>
                        </div>
                    </div>
                    <div class="form-group">
                        <a class="btn btn-default btn-block" href="User_Members.php">我的快乐家族</a>
                    </div>
                    <div class="form-group">
                        <a class="btn btn-default btn-block"
                           href="Share_User.php?id=<?php echo $user["id"]; ?>">邀请好友</a>
                    </div>
                    <div class="form-group">
                        <div class="input-group" style="width: 100%;">
                            <div class="input-group-addon" style="text-align:right;width: 90px">姓名：</div>
                            <input class="form-control" id="name" value="<?php echo $user["name"]; ?>">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group" style="width: 100%;">
                            <div class="input-group-addon" style="text-align:right;width: 90px">手机号：</div>
                            <input class="form-control" id="tel" value="<?php echo $user["phone"]; ?>">
                        </div>
                    </div>
                    <div class="btn btn-default btn-block" id="btn_update" disabled="disabled">确认修改</div>
                </div>
            </div>
            <div class="list-group">
                <div class="list-group-item">
                    消费:<a href="expend_inquiry.php"><?php echo "￥" . $user["expend"] . "元"; ?></a>
                    <?php if($zt){?>
                    <span id="lwicon" class="glyphicon glyphicon-gift text-danger" style="float: right;"></span>
                    <?php } ?>
                </div>
                <div class="list-group-item">
                    佣金:<a href="bonus_inquiry.php"><?php echo "￥" . $user["remain_bonus"] . "元"; ?></a>
                    <a style="float: right;" href='Withdraw_inquiry.php'>
                        <?php echo "(申请中:￥" . $money . "元)" ?>
                    </a>
                </div>
                <div class="list-group-item">
                    <button class="btn btn-default btn-block" id="withdraw" ontouchend="tx(<?php echo $money ?>)">申请提现
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <!--            <div id="bank_panel" align="center">
                <?php
            /*                for ($a = 0; $a < count($bank_card); $a++) {
                                $num = substr($bank_card[$a]["card_num"], count($bank_card[$a]["card_num"]) - 5);
                                $id = $bank_card[$a]["id"];
                                */ ?>
                    <div class="bank_card" onclick="set_bank(<?php /*echo $id; */ ?>)">
                        <div class="bank_msg"><?php /*echo $bank_card[$a]["bank_name"] */ ?></div>
                        <div class="card_msg">**** **** **** <?php /*echo $num; */ ?></div>
                    </div>

                <?php /*} */ ?>
            </div>-->

            <?php
            for ($a = 0; $a < count($bank_card); $a++) {
                $num = substr($bank_card[$a]["card_num"], count($bank_card[$a]["card_num"]) - 5);
                $id = $bank_card[$a]["id"];
                ?>
                <div class="panel" ontouchend="set_bank(<?php echo $id; ?>)">
                    <div class="panel-heading">
                        <div class="panel-title"><?php echo $bank_card[$a]["bank_name"] ?></div>
                    </div>
                    <div class="panel-body">**** **** **** <?php echo $num; ?></div>
                </div>
            <?php } ?>


            <button class="btn btn-default btn-block" style="margin-bottom: 15px;" id="addbank">添加银行卡</button>
        </div>
    </div>


    <!--<div id="top">
        <div id="head_icon" style="background: url('<?php /*echo $user_icon; */ ?>');background-size:100% 100%;">
            <form id="save_icon" method="post" enctype="multipart/form-data">
                <input id="fileInput"  name="icon" type="file" onchange="input_icon('<?php /*echo $user_icon; */ ?>')">
            </form>
        </div>
        <div id="information">
            <div>
                姓名:<input id="name" value="<?php /*echo $user["name"]; */ ?>">
            </div>
            <div>
                手机号:<input type="text" id="tel" value="<?php /*echo $user["phone"]; */ ?>">
            </div>
            <div><a href="User_Members.php">乐巢家族</a></div>
        </div>
    </div>-->


</div>
<div class="modal" id="msg_modal" style="z-index: 999;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <div class="modal-title">提示</div>
            </div>
            <div class="modal-body"></div>
        </div>
    </div>
</div>
<script>

    var old_name = $('#name').val();
    var old_tel = $('#tel').val();

    function input_icon(old_img) {
        var img = $("#fileInput").val();
        var hz = img.substring(img.lastIndexOf(".") + 1).toLocaleLowerCase();


        if (img != "") {
            if (hz == "png" || hz == "bmp" || hz == "jpeg" || hz == "jpg" || hz == "gif") {
                document.getElementById("head_icon").style.background = "url('../wap/system_icon/input_msg.jpg')";
                document.getElementById("head_icon").style.backgroundSize = "100% 100%";
                var save = new FormData($("#save_icon")[0]);
                $.ajax({
                    url: "fun_save_icon.php",
                    type: "post",
                    data: save,
                    success: function (o) {
                        if (o != "失败") {
                            setTimeout(function () {
                                document.getElementById("head_icon").style.background = "url('../wap/system_icon/input_success.jpg')";
                                document.getElementById("head_icon").style.backgroundSize = "100% 100%";
                            }, 1000);
                            setTimeout(function () {
                                document.getElementById("head_icon").style.background = "url(" + o + ")";
                                document.getElementById("head_icon").style.backgroundSize = "100% 100%";
                            }, 2000);
                        } else {
                            setTimeout(function () {
                                document.getElementById("head_icon").style.background = "url('../wap/system_icon/input_error.jpg')";
                                document.getElementById("head_icon").style.backgroundSize = "100% 100%";
                            }, 1000);
                            setTimeout(function () {
                                document.getElementById("head_icon").style.background = "url(" + old_img + ")";
                                document.getElementById("head_icon").style.backgroundSize = "100% 100%";
                            }, 2000);

                        }
                    },
                    error: function () {
                        setTimeout(function () {
                            document.getElementById("head_icon").style.background = "url('../wap/system_icon/input_error.jpg')";
                            document.getElementById("head_icon").style.backgroundSize = "100% 100%";
                        }, 1000);
                        setTimeout(function () {
                            document.getElementById("head_icon").style.background = "url(" + old_img + ")";
                            document.getElementById("head_icon").style.backgroundSize = "100% 100%";
                        }, 2000);
                    },
                    processData: false,
                    contentType: false
                });
            }
        }
        $("#fileInput").val("");
        return false;
    }

    $('#addbank').on("touchend",function () {
        location.href = "Add_Bank.php";
    });
    function tx(money) {
        location.href = "User_Withdraw.php?money=" + money;
    }
    ;


    function set_bank(id) {
        location.href = "Set_Bank.php?id=" + id;
    }

    $(function () {
        var name = $("#name").val(), tel = $("#tel").val();

        $("#name,#tel").change(function () {
            if ($("#name").val() == name && $("#tel").val() == tel) {
                $('#btn_update').removeClass("btn-primary").addClass("btn-default").attr('disabled', 'disabled');
            } else {
                $('#btn_update').removeAttr('disabled').removeClass("btn-default").addClass("btn-primary");
            }
        });
        $("#btn_update").on("touchend", function () {
            var $this = $(this), $this_text = $(this).text();
            $this.attr('disabled', 'disabled').text("正在修改...");
            var n = $("#name").val(),
                t = $("#tel").val();
            if (t && !(/^1[3|4|5|6|7|8|9]\d{9}$/.test(t))) {
                $('#msg_modal').modal('show').find(".modal-body").html("请输入正确的大陆手机号！");
                return;
            }
            $.post("fun_update_user.php", {name: n, tel: t}, function (o) {
                $this.removeAttr('disabled').html($this_text);
                if (o == "") {
                    name = n, tel = t;
                    $('#btn_update').removeClass("btn-primary").addClass("btn-default").attr('disabled', 'disabled');
                    return;
                }
                $('#msg_modal').modal('show').find(".modal-body").html("更新数据失败！请稍后重试");
            });
        });

        setInterval(function () {
            $("#lwicon").fadeToggle(1000);
        }, 200);

    });
    $(function() {
        $("[ontouchend]").each(function(index, element) {
            var moved = false;
            var bindFn = function(touchEndFn) {
                if (!moved) {
                    eval(touchEndFn);
                }
                moved = false;
            }
            $(this).bind("touchend", bindFn.bind(this, $(this).attr("ontouchend")));
            $(this).bind("touchmove", function() {
                moved = true;
            });
            $(this).removeAttr("ontouchend");
        });

    })
</script>
</body>
</html>
